$(()=>{
    findById(id);
    console.log("要回显的id:"+id)

    //渲染出生日期
    layui.use(function () {
        const laydate = layui.laydate;
        laydate.render({
            elem: "#birthday",
            type: "date"
        });
    });
})

function submitEdit(cb=$.noop){
    // console.log("确定修改的id"+id)
    let cardId=$("#cardId").val();
    let name=$("#name").val();
    let pinyin=$("#pinyin").val();
    let phone=$("#phone").val();
    let birthday=$("#birthday").val();
    let weixin=$("#weixin").val();
    let sex=$(":input[name=sex]:checked").val();
    // console.log(cardId,name,sex,phone,pinyin,weixin)
    if (cardId.trim()===""){
        layer.msg("请输入学号");
        return;
    }
    if (name.trim()===""){
        layer.msg("请输入姓名");
    }

    $.ajax({
        url:ctx+"/admin/student/edit?id="+id,
        method:"POST",
        data:{
            cardId,
            name,
            sex,
            phone,
            pinyin,
            weixin,
            birthday
        },
        success:function(data){
          cb(data.success)
        }
    })

}
function findById(id){
    $.ajax({
        url:ctx+"/admin/student/id",
        method:"get",
        data:{
            id
        },
        dataType:"json",
        success:function(data){
            // console.log("开始赋值"+data)
            const student = data.student;
            console.log("要回显的对象"+student)
            $("#cardId").val(student.cardId);
            $("#name").val(student.name);
            $("#phone").val(student.phone);
            $("#birthday").val(student.birthday);
            $("#weixin").val(student.weixin);
            $("#pinyin").val(student.pinyin);

            //单选框回显
            $(":radio[name=sex][value="+student.sex+"]").prop("checked",true)
        }
    })
}